﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PKURG.CostSplit.Business.QueryBase;

namespace PKURG.CostSplit.Business
{
    public class DetailSplit
    {
        public static List<dynamic> GetProjectStageAccountData(int projectStageId)
        {
            return ExecuteQuery.GetList(
                new QueryBase.QueryInfo()
                {
                    ProcName = "usp_GetProjectStageAccountData",
                    Params = { projectStageId }
                });
        }


        public static List<dynamic> GetProjectStageMData(int projectStageId)
        {
            return ExecuteQuery.GetList(
                new QueryBase.QueryInfo()
                {
                    ProcName = "usp_GetProjectStageMData",
                    Params = { projectStageId }
                });
        }

        public static List<dynamic> GetDetailSplitInfoAtOnce(int projectStageId, int type)
        {
            return ExecuteQuery.GetList(
                new QueryBase.QueryInfo()
                {
                    ProcName = "usp_GetDetailSplitInfoAtOnce",
                    Params = { projectStageId, type }
                });
        }

        public static bool CreateDetailItemInfo(Guid detailItemId, Guid accountItemId, Guid buidingItemId, int type)
        {
            Entities.DetailSplit info = new PKURG.CostSplit.Services.DetailSplitService().Save(new Entities.DetailSplit()
             {
                 Id = detailItemId,
                 Account = accountItemId,
                 BuildingId = buidingItemId,
                 DataType = type

             });
            if (info == null)
            {
                return false;
            }
            return true;
        }

        public static int UpDateDetailItemInfo(Guid detailItemId, decimal value)
        {
            return QueryBase.CustomProcess.ExecuteProcNonQuery("ups_UpDateDetailItemInfo", new Object[] { detailItemId.ToString(), value });
        }


        public static List<dynamic> GetDetailSplitList(string contractId)
        {
            return ExecuteQuery.GetList(
                new QueryBase.QueryInfo()
                {
                    ProcName = "usp_n_GetDetailSplitList",
                    Params = { contractId }
                });
        }
        public static List<dynamic> GetDetailSplitList_UnHappend(string contractId)
        {
            return ExecuteQuery.GetList(
                new QueryBase.QueryInfo()
                {
                    ProcName = "usp_n_GetDetailSplitList_UnHappend",
                    Params = { contractId }
                });
        }

        public static int AddContractSplit(string contractCostId, string businessType, int processType, decimal value)
        {
            return QueryBase.CustomProcess.ExecuteProcNonQuery("usp_n_AddContractSplit", new Object[] { Guid.NewGuid().ToString(), contractCostId, businessType, processType, value });
        }

        public static int DelContractSplit(string contractCostId, string businessType, int processType)
        {
            return QueryBase.CustomProcess.ExecuteProcNonQuery("usp_n_DelContractSplit", new Object[] { contractCostId, businessType, processType });
        }

        public static void UpdateContractCost(Guid id, int type, int updateType, string reason)
        {
            if (updateType == 0)
            {
                 QueryBase.CustomProcess.ExecuteProcNonQuery("usp_n_UpdateContractCost_ApportionAreaType", new Object[] { id.ToString(), type ,reason});

            }
            else
            {
                QueryBase.CustomProcess.ExecuteProcNonQuery("usp_n_UpdateContractCost_ApportionAreaType_UnHappen", new Object[] { id.ToString(), type ,reason});

            }
        }
    }
}
